<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
 <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
 <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.0.0-beta/css/bootstrap.min.css">
 <script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script>
 <script src="https://cdn.bootcss.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>
<link href="../../ico.ico" rel="icon" type="image/x-icon" />
  <script>
  // location.href='https://wxydt.yidianting.xin/weixin/html/visit/ydtVisitorIndex.do?sd=1&si=1&sp=1&parkId=4266&code=061UBEhO1V0mM31QbljO1DnGhO1UBEhs'
  </script>
</head>
   
<script src="http://momentjs.cn/downloads/moment.js"></script>
<body style="background: url(/jd/images/car/car.png);background-size:100% ">
  <div class="container">
    <div style="margin: auto;margin-top: 170px;margin-left:20px;text-align: center;color:#fff;">
      <div>用户通过授权时，会变成绿色，15s</div>
      <br>
      <button type="button" class="btn btn-danger" id="show">等待授权</button>
    </div>
  </div>
 <script> 

  $(function  () {

let view=""
var ws = new WebSocket("ws://minmm.uicp.cn:80");

     ws.onopen = function(e) {

             $('#sub').click(function  () {
                var data={}
               data.group="0"
               data.name='user'
               data.toname='admin'
               data.message=$('#text').val()
               data=JSON.stringify(data)
               ws.send(data);
             
           
           })
}
     

  ws.onmessage = function (evt) 
  { 

     var received_msg = JSON.parse(evt.data);
     console.log(received_msg.message)
     $('#show').addClass('btn-success')
     $('#show').removeClass('btn-danger')
     $('#show').text('授权成功'+received_msg.message.split(',')[1])

     setTimeout(function () {
      $('#show').text('等待授权')
      $('#show').addClass('btn-danger')
      $('#show').removeClass('btn-success')
     },15000)
    //  if(received_msg.toname=='user'){
    //    let message=received_msg.message
    //        name=received_msg.name
           
           
    //       // view+=received_msg.name+'说：'+received_msg.message+'<br />'
          
    //       // $('#show').html(view)
    //  }

    
  };

//             ws.onclose = function()
//             { 
//                // 关闭 websocket
//                alert("连接已关闭..."); 
//             };
    ws.onerror = function(event) {
     console.log(event)
};
  
//          }
//          
//          else
//          {
//             // 浏览器不支持 WebSocket
//             alert("您的浏览器不支持 WebSocket!");
//          }


})
  </script>
</body>
</html>